package com.ytjj.qmyx.mall.utils;

import org.apache.commons.lang3.StringUtils;

public class InfoAesUtil {

    public static void main(String[] args) {
        System.out.println(aesPhone("18873058010"));
        System.out.println(aesAddress("湖南省岳阳市君山区广兴洲镇"));
        System.out.println(aesExpressNo("JD4975456123"));
        System.out.println(aesName("姜康"));
    }

    public static String aesPhone(String phone) {
        if (StringUtils.isEmpty(phone)) {
            return "";
        }
        if (phone.length() < 11) {
            return phone;
        }
        return phone.replace(phone.substring(3, 7), "***");
    }

    public static String aesAddress(String address) {
        if (StringUtils.isEmpty(address)) {
            return "";
        }
        if (address.length() < 10) {
            return address;
        }
        return address.replace(address.substring(address.length() - 5, address.length()), "***");
    }

    public static String aesExpressNo(String expressNo) {
        if (StringUtils.isEmpty(expressNo)) {
            return "";
        }
        if (expressNo.length() < 4) {
            return expressNo;
        }
        int startIndex = (expressNo.length() - 4) / 2;
        return expressNo.substring(0, startIndex) + "***" + expressNo.substring(startIndex + 4);
    }

    public static String aesName(String name) {
        if (StringUtils.isEmpty(name)) {
            return "";
        }
        if (name.length() < 2) {
            return name;
        }
        return name.substring(0, 1) + "**";
    }
}
